
open Ast

module StrMap = Map.Make(String)

let extract_funcDecls ast =
	List.fold_left (fun (decls,ast) e ->
		(match e with
			| AStatement stmt ->
				(match stmt with
					| AFuncDeclaration decl -> decls@[e], ast
					| _ -> decls, ast@[e])
			(*| AFunctionDeclaration(funcDecl) -> fullfill_functionDeclaration data funcDecl *) (* Modif #1 *)
		)) ([],[]) ast

let move_funcDecls_to_left ast =
	let decls, ast = extract_funcDecls ast in
	decls@ast
	
let move_funcDecls_to_right ast =
	let decls, ast = extract_funcDecls ast in
	ast@decls

let funcDecls_to_map ast =
	List.fold_left (fun decls e ->
		(match e with
			| AStatement stmt ->
				(match stmt with
					| AFuncDeclaration (_, _, inline, ident, params, body) -> (StrMap.add ident (inline,params,body) decls)
					| _ -> decls)
			(*| AFunctionDeclaration(funcDecl) -> fullfill_functionDeclaration data funcDecl *) (* Modif #1 *)
		)) StrMap.empty ast
